package com.decent.ejfadmin.common.bean;

import com.decent.ejfadmin.common.enums.SubmitCardApplyEnum;
import lombok.Data;
import org.apache.commons.lang3.time.DateFormatUtils;

import java.math.BigDecimal;
import java.util.Date;

/**
 * describe: sup会员信息
 *
 * @author JunLei He
 * @date 2018年07月06日
 */
@Data
public class SupUser {
    /**
     * 用户id
     */
    private Long userId;
    /**
     * 登录账号
     */
    private String account;
    /**
     * 用户状态 0 开启 1关闭
     */
    private Integer status;
    /**
     * 产品经理
     */
    private Integer pmId;
    /**
     * 登录密码
     */
    private String loginPwd;
    /**
     * 支付密码
     */
    private String payPwd;
    /**
     * 销卡模板
     */
    private Long supplyModel;
    /**
     * 绑定ip
     */
    private String ip;
    /**
     * 平台类型 用户来源 0 web 1 weixin 2 app
     */
    private Integer type;
    /**
     * 会员密钥
     */
    private String userKey;
    /**
     * 推荐人
     */
    private Long recommendId;
    /**
     * 登录时间
     */
    private Date loginTime;
    /**
     * api权限
     */
    private Integer apiState;
    /**
     * 有效还是无效
     */
    private Integer validState;
    /**
     * 注册时间
     */
    private Date registeTime;
    /**
     * 模板名称
     */
    private String modelName;
    /**
     * 注册备注
     */
    private String registeRemark;
    /**
     * 会员信息
     */
    private SupInfo supInfo;
    /**
     * 会员权限
     */
    private SupPrivilege supPrivilege;
    /**
     * 专属管理员
     */
    private UserPm userPm;
    /**
     * 回调地址
     */
    private String notifyUrl;
    /**
     * 会员id
     */
    private String userIds;
    /**
     * 是否为单独密价
     */
    private Integer isPrivatePrice;
    /**
     * 旧平台回调地址
     */
    private String callBackUrl;
    /**
     * 新旧api会员 0 新用户 1老用户
     */
    private Integer apiType;
    /**
     * 权益信用分
     */
    private BigDecimal equityCredit;
    /**
     * Q币大额权限
     */
    private Integer qbLargeAmountConfig;
    /**
     * Q币大额金额
     */
    private BigDecimal qbLargeAmount;
    /**
     * 权益api状态
     */
    private Integer equityApiState;
    /**
     * 提卡申请
     */
    private SubmitCardApplyEnum submitCardApply;
    /**
     * 日提卡限额
     */
    private Integer dailySupplyLimit;
    /**
     * 实体卡限制（true：实体卡，需判断移动+电信+联通非98卡；false：电子卡，判断联通98卡）
     */
    private Boolean entityLimit;

    public SupUser(String account, String ip, Integer type) {
        this.account = account;
        this.ip = ip;
        this.type = type;
    }

    public SupUser(String account, String loginPwd, String ip, Integer type) {
        this.account = account;
        this.loginPwd = loginPwd;
        this.ip = ip;
        this.type = type;
    }

    public SupUser() {
    }

    public SupUser(Long userId) {
        this.userId = userId;
    }

    public SupUser(SupInfo supInfo) {
        this.supInfo = supInfo;
    }

    String getTypeName(Integer type) {
        if (type == null) {
            return "-";
        }
        switch (type) {
            case 0:
                return "web";
            case 1:
                return "微信";
            case 2:
                return "app";
            case 3:
                return "易缴费";
            default:
                return "-";
        }
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder(100);
        sb.append("=\"").append(getAccount()).append("\"");
        sb.append(",=\"").append(getSupInfo() == null ? "" : supInfo.getName()).append("\"");
        sb.append(",").append(getStatus() == 0 ? "关闭" : "开启");
        sb.append(",").append(getApiState() == 0 ? "关闭" : "开启");
        sb.append(",").append(getEquityApiState() == 0 ? "关闭" : "开启");
        sb.append(",").append(SubmitCardApplyEnum.convert(getSubmitCardApply()));
        sb.append(",").append(getModelName());
        sb.append(",").append(DateFormatUtils.format(getRegisteTime(), "yyyy-MM-dd HH:mm:ss"));
        sb.append(",").append(getUserPm() == null ? "" : getUserPm().getName());
        sb.append(",").append(getTypeName(getType()));
        sb.append(",").append(getIp());
        sb.append(",").append(getEquityCredit());
        sb.append("\r\n");
        return sb.toString();
    }
}
